import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/views/login'
import Layout from '@/layout/layout'

Vue.use(Router)

/**
 * alwaysShow: true           if set true, will always show the root menu, whatever its child routes length
 *                            if not set alwaysShow, only more than ont route under the children
 *                            it will becomes nested mode, otherwise not show the root menu
 * alwaysShow: true           如果设置为true,它将总是现在在根目录。如果不设置的话，当它只有1个子路由的时候，会把
 *                            它的唯一子路由放到跟目录上来，而不显示它自己本身。
 */

export const constantRouterMap = [
  {
    path: '/login',
    name: 'login',
    hidden: true,
    component: Login,
    meta: {
      title: '登录'
    }
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/',
    hidden: true,
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/homepage'),
        meta: { title: '首页' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    meta: {
      icon: 'tickets',
      title: '个人中心'
    },
    children: [
      {
        path: 'profile',
        name: 'Profile',
        component: () => import('@/views/user/profile'),
        meta: { icon: 'warning', title: '个人中心' }
      },
      {
        path: 'avatar',
        name: 'Avatar',
        component: () => import('@/views/user/profile'),
        meta: { icon: 'warning', title: '修改头像' }
      }
    ]
  },

  //产品管理
  {
    path: '/product',
    component: Layout,
    redirect: '/product/index',
    // alwaysShow: true,
    meta: {
      icon: 'svg-aperture',
      title: '产品管理'
    },
    children: [
      {
        path: 'index',
        name: 'product',
        component: () => import('@/views/product/index'),
        meta: { icon: 'svg-aperture', title: '产品管理' }
      }
    ]
  },

  //分类管理
  {
    path: '/category',
    component: Layout,
    redirect: '/category/index',
    // alwaysShow: true,
    meta: {
      icon: 's-grid',
      title: '分类管理'
    },
    children: [
      {
        path: 'index',
        name: 'category',
        component: () => import('@/views/category/index'),
        meta: { icon: 's-grid', title: '分类管理' }
      }
    ]
  },

  //用户管理
  {
    path: '/customer',
    component: Layout,
    redirect: '/customer/index',
    // alwaysShow: true,
    meta: {
      icon: 'svg-heart',
      title: '用户管理'
    },
    children: [
      {
        path: 'index',
        name: 'customer',
        component: () => import('@/views/customer/index'),
        meta: { icon: 'svg-heart', title: '用户管理' }
      }
    ]
  },

  //地址管理
  {
    path: '/address',
    component: Layout,
    redirect: '/address/index',
    // alwaysShow: true,
    meta: {
      icon: 'guide',
      title: '地址管理'
    },
    children: [
      {
        path: 'index',
        name: 'address',
        component: () => import('@/views/address/index'),
        meta: { icon: 'guide', title: '地址管理' }
      }
    ]
  },

  //订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/index',
    // alwaysShow: true,
    meta: {
      icon: 'svg-aperture',
      title: '订单管理'
    },
    children: [
      {
        path: 'index',
        name: 'order',
        component: () => import('@/views/order/index'),
        meta: { icon: 'star-on', title: '订单管理' }
      }
    ]
  },

  //系统设置
  {
    path: '/system',
    component: Layout,
    redirect: '/system/role',
    // alwaysShow: true,
    meta: {
      icon: 'svg-layers',
      title: '系统设置'
    },
    children: [
      {
        path: 'role',
        name: 'system',
        component: () => import('@/views/system/role'),
        meta: { icon: 'document', title: '角色管理' }
      },
      {
        path: 'privilege',
        name: 'system',
        component: () => import('@/views/system/privilege'),
        meta: { icon: 'document', title: '权限管理' }
      }
    ]
  },

  //审核管理
  {
    path: '/check',
    component: Layout,
    redirect: '/check/comment',
    // alwaysShow: true,
    meta: {
      icon: 'svg-droplet',
      title: '审核管理'
    },
    children: [
      {
        path: 'comment',
        name: 'check',
        component: () => import('@/views/check/comment'),
        meta: { icon: 'warning', title: '评论审核' }
      },
      {
        path: 'employee',
        name: 'check',
        component: () => import('@/views/check/employee'),
        meta: { icon: 'warning', title: '员工审核' }
      },
      {
        path: 'withdraw',
        name: 'check',
        component: () => import('@/views/check/withdraw'),
        meta: { icon: 'warning', title: '提现审核' }
      }
    ]
  },

]

export default new Router({
  // mode: 'history',  require service support
  // scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/theme',
    component: Layout,
    meta: {
      icon: 'document',
      title: 'theme'
    },
    children: [
      {
        path: 'index',
        component: () => import('@/views/theme/index'),
        name: 'Theme',
        meta: { title: '主题', icon: 'svg-pifu' }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]